/**
 * Created by zhangshun on 2018/8/10.
 */
var payUtil = require("wxPayUtil.js");
module.exports = {
    //支付
    getPayU:function(){
        var rechargeParamJson = {
            memberId: app.globalData.loginUserInfo.id,
            openId: app.globalData.loginUserInfo.openId,
            rechargeAmount: 1
        }
        //支付
        wx.request({
            url: app.globalData.baseUrl + '/member/recharge/rechargePayment',
            data: JSON.stringify(rechargeParamJson),
            method: 'POST',
            success: function (res) {
                //调用成功
                var prepayId = res.data.data.prepayId;
                var appId = res.data.data.appId;
                var key = res.data.data.mchApiSecretKey;
                console.log("调用支付接口成功" + res);
                var timeStamp = payUtil.getTimeStamp();
                var nonceStr = payUtil.getNonceStr();
                var packages = "prepay_id=" + prepayId;
                var signType = payUtil.getMD5SignType();
                var paySign = payUtil.getSign(appId,nonceStr,timeStamp,prepayId,signType,key);
                console.log("加密paySign="+paySign);
                wx.requestPayment({
                    timeStamp: timeStamp,
                    nonceStr: nonceStr,
                    package: packages,
                    signType: signType,
                    paySign: paySign,
                    success: function (res) {//支付完成
                        console.log("支付付成功"+JSON.stringify(res.data));
                    },
                    fail: function (res) {//支付失败
                        console.log("支付付失败" + JSON.stringify(res.data));
                    },
                    complete: function (res) {//回调
                        console.log("支付付完成" + JSON.stringify(res.data));
                    }
                })
            },
            fail: function (res) {
                //调用失败
                console.log("调用支付接口失败" + res);
            },
            complete: function (res) {
                console.log("调用支付接口完成" + res);
            }
        })
    }

};